package com.zhanglifan.util;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Information
 * Author: ZhangLifan
 * Time: 2017/10/9 13:10
 * Description: CstUtils
 */
public class CstUtils {
    //反射调用操作的都是对象的实例(类加载器中的数据),不受多态的影响,不需要进行转型.
    public static  void changeStatus(Object baseService, Class entityCLs,String[] ids , int status){
        for (String id : ids) {
            try {
                Class bsCls = baseService.getClass();
                Method method = bsCls.getMethod("get", Class.class, Serializable.class);
                Object entity = method.invoke(baseService, entityCLs, id);

                Class eCls = entity.getClass();
                Method m = eCls.getMethod("setState",Integer.class);
                m.invoke(entity,status);
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
    }
}
